package com.yjhb.android.sbz.mvp.sendredpack;

import com.yjhb.android.sbz.entity.RedPackDetails;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.math.BigDecimal;

/**
 * 创建者 zx
 * 创建时间 2021/1/13 17:47
 */
public class SendRedPackPresenter extends ConventionPresenter<SendRedPackView> {
    private final String TAG = "SendRedPackPresenter";

    @Override
    protected void onDestroy() {

    }

    public SendRedPackPresenter(SendRedPackView sendRedPackView) {
        super(sendRedPackView);
    }

    public void send(String title, Integer taskId, BigDecimal money, int stock) {
        if (view != null) {
            view.onWait();
        }
        HttpTool.request(model.sendRedPack(title, taskId, money, stock), new HttpObserver<Object>() {
            @Override
            public void onResult(Object data) {
                if (view != null) {
                    view.onSuccess(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

    public void queryRedPacket(Integer taskId) {
        if (view != null) {
            view.onWait();
        }
        HttpTool.request(model.queryRedPacket(taskId), new HttpObserver<RedPackDetails>() {
            @Override
            public void onResult(RedPackDetails data) {
                if (view != null) {
                    view.onDetail(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }
}
